package com.ruoyi.youtian.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.AutoSetDefaultParams;
import com.ruoyi.youtian.domain.PointAttribute;
import com.ruoyi.youtian.service.IPointAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 监测点属性Controller
 *
 * @author ruoyi
 * @date 2022-09-15
 */
@RestController
@RequestMapping("/youtian/pointAttribute")
public class PointAttributeController extends BaseController
{
    @Autowired
    private IPointAttributeService pointAttributeService;

    /**
     * 查询监测点属性列表
     */
//    @PreAuthorize("@ss.hasPermi('system:attribute:list')")
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(PointAttribute pointAttribute)
    {
        startPage();
        List<PointAttribute> list = pointAttributeService.selectPointAttributeList(pointAttribute);
        return getDataTable(list);
    }

    /**
     * 导出监测点属性列表
     */
//    @PreAuthorize("@ss.hasPermi('system:attribute:export')")
    @Log(title = "监测点属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PointAttribute pointAttribute)
    {
        List<PointAttribute> list = pointAttributeService.selectPointAttributeList(pointAttribute);
        ExcelUtil<PointAttribute> util = new ExcelUtil<PointAttribute>(PointAttribute.class);
        util.exportExcel(response, list, "监测点属性数据");
    }

    /**
     * 获取监测点属性详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:attribute:query')")
    @GetMapping(value = "/{id}")
    @ResponseBody
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pointAttributeService.selectPointAttributeById(id));
    }

    /**
     * 新增监测点属性
     */
//    @PreAuthorize("@ss.hasPermi('system:attribute:add')")
    @Log(title = "监测点属性", businessType = BusinessType.INSERT)
    @PostMapping
    @ResponseBody
    @AutoSetDefaultParams
    public AjaxResult add(@RequestBody PointAttribute pointAttribute)
    {
        return toAjax(pointAttributeService.insertPointAttribute(pointAttribute));
    }

    /**
     * 修改监测点属性
     */
//    @PreAuthorize("@ss.hasPermi('system:attribute:edit')")
    @Log(title = "监测点属性", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    @ResponseBody
    @AutoSetDefaultParams
    public AjaxResult edit(@RequestBody PointAttribute pointAttribute)
    {
        return toAjax(pointAttributeService.updatePointAttribute(pointAttribute));
    }


    /**
     * 删除监测点属性
     */
//    @PreAuthorize("@ss.hasPermi('system:attribute:remove')")
    @Log(title = "监测点属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ResponseBody
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pointAttributeService.deletePointAttributeByIds(ids));
    }
}
